import {message} from 'nuijs';
module.exports = function($elem){
    return{
        valid:{
            onfocusout:function (elem) {
                $(elem).valid();
            },  
            errorPlacement:function(error, element) {
                if(error.text()){
                    element.next('.err').html(error);
                }
            }
        },
        onBeforeSubmit(self,params){
            let main = self.main;
            let selectItem = main.find('.u-select.s-selected');
            let capability =[];
            $.each(selectItem,function(k,val){
                capability.push($(val).data('name'))
            })
            params.capability = JSON.stringify(capability);
            return params;
        },
        onSuccess(self, res, xhr, param){
            if(res.result == 'success'){
                self.hide();
                message('success','调整成功');
            }else{
                message('error',res.message);
            }
        }
    }
}